
#delimit ;

log using Lemieux_et_al_PP_by_Earnings, replace text;

u psid7899_mar08;

keep if status==1;


drop if year==98 & tenure<1;
replace avhrly=(avhrly/cpi)*100;
drop if avhrly<1.5 | avhrly>100;
replace hdlaby=(hdlaby/cpi)*100;


replace comm=comm==1 | (commis>0 & commis~=.) | piece==1;
replace boni= (bonus>0 & bonus~=.) | comm==1;


gen exp2=potexp*potexp;
gen exp3=potexp*exp2;




egen numobs=count(id), by(jobmatch);

egen maxbon=max(boni), by(jobmatch); /* create bonus job dummy */

*pause;

*replace iweight=iweight*hours;

tab numobs [aw=iweight] if year>=82 & year<=90;

ta year, ge(y); *Create period-specific dummy variables, y;
ta numobs, ge(num); *Create number-of-times-observed dummies, num;

summ num1 if year>=82 & year<=90 [aw=iweight]; 
replace num1=num1-r(mean);  
summ num2 if year>=82 & year<=90 [aw=iweight]; 
replace num2=num2-r(mean);  
summ num3 if year>=82 & year<=90 [aw=iweight]; 
replace num3=num3-r(mean);   
summ num4 if year>=82 & year<=90 [aw=iweight]; 
replace num4=num4-r(mean);  
summ num5 if year>=82 & year<=90 [aw=iweight]; 
replace num5=num5-r(mean);   
summ num6 if year>=82 & year<=90 [aw=iweight]; 
replace num6=num6-r(mean);  
summ num7 if year>=82 & year<=90 [aw=iweight]; 
replace num7=num7-r(mean);  
summ num8 if year>=82 & year<=90 [aw=iweight]; 
replace num8=num8-r(mean); 
summ num9 if year>=82 & year<=90 [aw=iweight]; 
replace num9=num9-r(mean);   
summ num10 if year>=82 & year<=90 [aw=iweight]; 
replace num10=num10-r(mean);   
summ num11 if year>=82 & year<=90 [aw=iweight]; 
replace num11=num11-r(mean);    
summ num12 if year>=82 & year<=90 [aw=iweight]; 
replace num12=num12-r(mean);  
summ num13 if year>=82 & year<=90 [aw=iweight]; 
replace num13=num13-r(mean);  
summ num14 if year>=82 & year<=90 [aw=iweight]; 
replace num14=num14-r(mean);  
summ num15 if year>=82 & year<=90 [aw=iweight]; 
replace num15=num15-r(mean);  
summ num16 if year>=82 & year<=90 [aw=iweight]; 
replace num16=num16-r(mean);   
summ num17 if year>=82 & year<=90 [aw=iweight]; 
replace num17=num17-r(mean);  
summ num18 if year>=82 & year<=90 [aw=iweight]; 
replace num18=num18-r(mean);  
summ num19 if year>=82 & year<=90 [aw=iweight]; 
replace num19=num19-r(mean);  
summ num20 if year>=82 & year<=90 [aw=iweight]; 
replace num20=num20-r(mean);   
summ num21 if year>=82 & year<=90 [aw=iweight]; 
replace num21=num21-r(mean); 
summ num22 if year>=82 & year<=90 [aw=iweight]; 
replace num22=num22-r(mean);   


replace iweight=iweight*hours;

*generate dummies for earnings quartiles for each year;
*ssc inst egenmore;
egen earnings_quart=xtile(hdlaby), nq(100) by(year) weights(iweight);
gen earnings_quartile1=(earnings_quart<=25);
gen earnings_quartile2=(earnings_quart>25&earnings_quart<=50);
gen earnings_quartile3=(earnings_quart>50&earnings_quart<=75);
gen earnings_quartile4=(earnings_quart>75&earnings_quart<=90);
gen earnings_quartile5=(earnings_quart>90&earnings_quart<=95);
gen earnings_quartile6=(earnings_quart>95);

*egen earnings_quart=xtile(hdlaby), nq(4) by(year) weights(iweight);

*gen earnings_quartile1=(earnings_quart==1);

*gen earnings_quartile2=(earnings_quart==2);

*gen earnings_quartile3=(earnings_quart==3);

*gen earnings_quartile4=(earnings_quart==4);


*xi: reg maxbon num1-num22 year##earnings_quart [aw=iweight], nocons;
xi: reg maxbon num1-num22 i.year year##earnings_quartile2 year##earnings_quartile3 year##earnings_quartile4 year##earnings_quartile5 year##earnings_quartile6 [aw=iweight], nocons;


 
 
